PRG 1.0 TXT

/*
	Hexagons Color Filter
*/

//-----------------------------------------------------------------------------
// [CONFIG]

include "..\program_include.ocf"

object Program
{
	ubo_data	= array /*UBO*/ {
		{ "inParams",	e_program_data.POSTPROCESS_PARAMS }
	}
	
	textures	= array /*ProgramTexture*/ {
		{ "unColorMap", e_texture.DIFFUSE }
	}
	
	uniforms	= array /*string*/ {
		"transform", "unTransform."
	}
}


//-----------------------------------------------------------------------------
// [VERTEX]

#version 330 core
#pragma optimize(on)

#define ATTR_POSITION	0
#define ATTR_TEXCOORD	2
#define ATTR_COLOR		1

layout(location = ATTR_POSITION)	in vec3 inPosition;
layout(location = ATTR_TEXCOORD)	in vec2 inTexcoord;


uniform struct Transform {
	mat4	Projection;
} unTransform;


out	TVertexData {
	vec2	vTexcoord;
} Output;


void main(void)
{
	gl_Position  	 = unTransform.Projection * vec4(inPosition, 1.0);
	Output.vTexcoord = inTexcoord;
}


//-----------------------------------------------------------------------------
// [FRAGMENT]

#version 330 core
#pragma optimize(on)

layout(location = 0, index = 0) out vec4	outColor;

uniform sampler2D	unColorMap;

layout (std140)
uniform inParams {
	float	fSize	= 0.01;
} unParams;


in	TVertexData {
	vec2	vTexcoord;
} Input;


float fn(in float x)
{
	const float a  = 0.01;
	const float b  = 1.0;
	const float Pi = 3.14159265359;
	
	return ( (4*b)/(Pi*a)*( sin(a)*sin(x) + (1/9)*sin(3*a)*sin(3*x) + (1/25)*sin(5*a)*sin(5*x) ) )*2;
}


vec4 Filter(in vec2 texcoord)
{
	float		c	= 1/unParams.fSize;
	vec4		ret = texture( unColorMap, texcoord );
	float		k	= abs( fn(texcoord.x*c) + fn(texcoord.y*c) + 0.15*fn(texcoord.x*c*3) );
	
	ret *= k > 0.5 ? 1.0 : 0.3;
	return ret;
}


void main()
{
	outColor = Filter( Input.vTexcoord );
}

// [END]
